package com.newworld.basketballfire.main.impl;

import com.newworld.basketballfire.main.bean.ActivityListParam;
import com.newworld.basketballfire.main.business.ActivityBusiness;
import com.newworld.basketballfire.main.utils.CommonUtils;
import com.newworld.basketballfire.service.delegate.ActivityServiceDelegate;
import com.newworld.basketballfire.service.exception.ServiceException;
import com.newworld.basketballfire.service.model.Activity;
import com.newworld.basketballfire.service.model.ActivityParams;
import com.newworld.basketballfire.service.model.ListResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * Created by George on 2019/3/31.
 * ActivityServiceDelegateImpl
 */
@Component
public class ActivityServiceDelegateImpl implements ActivityServiceDelegate {

    @Autowired
    private ActivityBusiness activityBusiness;

    @Override
    public Activity createActivity(ActivityParams activityParams) throws ServiceException {
        Activity activity = new Activity(activityParams);
        return activityBusiness.createActivity(activity);
    }

    @Override
    public Activity updateActivity(String id, ActivityParams activityParams) throws ServiceException {
        Activity activity = new Activity(activityParams);
        activity.setId(id);
        return activityBusiness.updateActivity(activity);
    }

    @Override
    public Activity getActivity(String id) throws ServiceException {
        return activityBusiness.getActivity(id);
    }

    @Override
    public void deleteActivity(String id) throws ServiceException {
        activityBusiness.deleteActivity(id);
    }

    @Override
    public ListResult<Activity> getActivityList(String id, Integer pageNo, Integer pageSize) throws ServiceException {
        ActivityListParam activityListParam = new ActivityListParam();
        activityListParam.setId(id);
        activityListParam.setPageSize(pageSize);
        activityListParam.setPageNo(pageNo);
        activityListParam.setCurIndex(CommonUtils.getCurIndex(pageNo, pageSize));
        return activityBusiness.getActivityList(activityListParam);
    }
}
